home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / ab20 / ab20_archive / tex / texify-1.12.lzh / TeXify.ced < prev    next >
Text File  |  1991-09-04  |  17KB  |  585 lines

  1. /********************************************************************************/
  2. /* ARexx program                 TeXify  V 1.12  (Jun 91)                       */
  3. /*                                                                              */
  4. /*                         Just put this ARexx program on a CygnusEd Fkey       */
  5. /*                         and edit your TeX source. When finish with editing,  */
  6. /*                         press the function key and you get your source       */
  7. /* Copyright 1990          showing up in TeXs preview. If not, you get your     */
  8. /* by Wolf-Juergen Faust   cursor positioned at the error position with an      */
  9. /* Am Dorfgarten 10        error message. For a new TeXify version call    FIDO    */
  10. /* W-6000 Frankfurt 50       +(49) 6173 2544 (HST DS) or contact me...            */
  11. /* Germany                                                                      */
  12. /* FIDO: 2:243/43.5 (Wolf Faust)                                                */
  13. /* UUCP: cbmehq!cbmger!venus!wfaust@cbmvax.commodore.com                        */
  14. /* Tel: +(49) 69 5486556                                                        */
  15. /*                                                                              */
  16. /*      YOU MUST ADOPT THE FIRST COMMANDS TO YOUR ENVIRONMENT !!!!!!!!!!!!      */
  17. /*      ==================================================================      */
  18. /*        (See the readme and ARexx files you MUST get with this file!)         */
  19. /* Versions needed:                                                             */
  20. /* ARexx  = V 1.15                                                              */
  21. /* CEDPro = V 2.00                                                              */
  22. /* TeX   >= V 3.1d                                                              */
  23. /********************************************************************************/
  24.  
  25.  
  26.  
  27. /* Now, here's the command for starting TeX in backround. I offer you           */
  28. /* two examples. One for WShell and one for the normal Commodore shell.         */
  29. /* Shutting down TeX is simple in WShell/Conman: klick on the closegadget.      */
  30. /* For the normal TeX shell you have to type the usual CTRL-F.                  */
  31.  
  32. /* Commodore Shell version: (change all paths according to your system !)       */
  33. cmd1 = 'echo >t:tex1 "stack 10000"'
  34. cmd2 = 'echo >t:tex2 "tex:c/tex -R"'
  35. cmd3 = 'echo >t:tex3 "endcli"'
  36. cmd4 = 'join t:tex1 t:tex2 t:tex3 to t:tex'
  37. /*cmd5 = 'NewShell CON:0/11/640/180/Press_CTRL-F_to_close FROM t:tex'*/
  38.  
  39.                             /***  OR  ***/
  40.  
  41. /* WShell version:    (change only cmd5 ! cmd1-4 as above !)                    */
  42. cmd5 = 'NewWsh FROM t:tex'
  43.  
  44. /* Preview startup command: (change path according to your system !)            */
  45. preview = "run >nil: <nil: tex:c/preview"
  46.  
  47. /* CEDPro startup command:  (change path according to your system !)            */
  48. ced = "dh0:c/ced"
  49.  
  50. /* Max. errors before TeXify stops TeX (default should be arround 3)            */
  51. errorcount = 3
  52.  
  53. /* Keyword for the TeX macropackage (default: "macropackage")                   */
  54. package = "macropackage"
  55.  
  56. /* path and command string for commo's "setenv" command */
  57. setpath = "setenv"
  58.  
  59. /* path and command string for commo's "getenv" command */
  60. getpath = "getenv"
  61.  
  62. /* Max. time needed for loading TeX, Preview... (default: 10)                   */
  63. timeout = 10
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
  75. /***  START        (don't change anything after this...)  ***/
  76. /*** Return ***/
  77. cr = '0A'X
  78.  
  79. /*** program receives answers ***/
  80. options results
  81.  
  82. /*** now lets get to business with CygnusEd ***/
  83. address 'rexx_ced'
  84.  
  85. /*** ask for the file name, sans directory of the current file ***/
  86. status 21
  87. srcfile = result
  88.  
  89. /*** What about the name ??! Valid ??***/
  90. last = lastpos('.',srcfile)
  91. do while ((srcfile = "") | (last=0))
  92.     if srcfile = "" then srcfile = "untitled.tex"
  93.     okay2 "ERROR ! TeXfile needs a name with suffix !"||cr||"Continue ?"
  94.     if result = 0 then exit 5
  95.     getfilename srcfile 'Give name for new TeX sourcefile...'
  96.     if result ~= "RESULT" then do
  97.         last = lastpos('.',result)
  98.         fullsrc = result
  99.         if last ~= 0 then do
  100.             save as result
  101.             status 21
  102.             srcfile = result
  103.             last = lastpos('.',srcfile)
  104.             end
  105.         else
  106.             srcfile = fullsrc
  107.         end
  108.     else
  109.         last = 0
  110.     end
  111.  
  112. /***  path+filename: maybe part of path is missing ! special code needed  ***/
  113. status 19
  114. fullsrc = result
  115. last = lastpos(':',fullsrc)
  116.  
  117. /*** current dir maybe needed for joining with incomplete path ***/
  118. status 75
  119. if last = 0 then fullsrc = result||fullsrc
  120. last = lastpos('/',fullsrc)
  121. if last~=0 then do
  122.     path = left(fullsrc,last)
  123.     texpath = left(fullsrc,last-1)
  124.     end
  125. else do
  126.     last = lastpos(':',fullsrc)
  127.     path = left(fullsrc,last)
  128.     texpath = path
  129.     end
  130.  
  131. /*** change suffix of source to .log later...***/
  132. srcnam = left(fullsrc,lastpos('.',fullsrc)-1)
  133.  
  134. /*** get suffix of current textfile ***/
  135. sfx = right(srcfile,length(srcfile)-lastpos('.',srcfile))
  136.  
  137. /*** is suffix .tex ?? maybe just a wrong key ?? ***/
  138. if upper(sfx) ~= 'TEX' then do
  139.     okay2 'Suffix ' sfx ' is not a TeX file !' cr||'Start TeX anyway ?'
  140.     if result = 0 then exit 5
  141.     end
  142.  
  143. /*** are there any changes ? do I have to save the text first ??  ***/
  144. status 18
  145. if result ~= 0 then do 
  146.     save
  147.     end
  148.  
  149. /*** look out for macropackage in textfile ***/
  150. status 46
  151. y = result 
  152. status 47
  153. x = result
  154. 'Beg of file'
  155. status 55
  156. macro = left(upper(result),length(result)-1)
  157.  
  158. 'Jumpto' x+1  y+1
  159. if left(macro,1) = "%" then do
  160.     macro = strip(strip(macro,'L','%'),'L')
  161.     if (pos(upper(package),macro) = 1) then do
  162.         macro = subword(strip(strip(substr(macro,length(package)+1),'L'),'L','='),1)
  163.         if pos('%',macro)>0 then do
  164.             macro = left(macro,pos('%',macro)-1)
  165.             end
  166.         macro = strip(macro,'T')
  167.         end
  168.         else macro = ""
  169.     end
  170.     else macro = ""
  171. if macro ~= "" then do
  172.     /*** get contents of texformat environment ***/
  173.     address command getpath||" >t:tex1 texformat"
  174.     ti = time('S') + 5;
  175.     rc = 0
  176.     do while ((rc=0) & (time('S') < ti))
  177.         rc = open('log','t:tex1')
  178.         if rc = 0 then call delay(50)
  179.         end
  180.     if rc = 0 then do
  181.         okay1 "INTERNAL ERROR ! Can't read temp. file for getting environment!"
  182.         exit 5
  183.         end
  184.     oldmacro = "PLAIN" /* default setting */
  185.     do until eof('log')
  186.         logline = upper(readln('log'))
  187.         if (length(logline)>0) then do
  188.             if (lastpos('/',logline)~=0) then logline = right(logline,length(logline)-lastpos('/',logline))
  189.             if (lastpos(':',logline)~=0) then logline = right(logline,length(logline)-lastpos(':',logline))
  190.             oldmacro = logline
  191.             end
  192.         end
  193.     call close 'log'
  194.     /*** set up new macropackage ***/
  195.     if oldmacro ~= macro then do
  196.         address command setpath||' texformat '||macro
  197.         if (show('P','AMIGATEX')) then do
  198.             address 'AMIGATEX' 'Exit'
  199.             delay(20)
  200.             end
  201.         end
  202.     end
  203. /*** It's time for support !  **/
  204. if ~show('l','rexxsupport.library') then
  205.    if ~addlib('rexxsupport.library',0,-30) then
  206.       do
  207.          Okay1 'Error ! No rexxsupport.library !'
  208.          exit 5
  209.          end
  210.  
  211. /*** Hey TeX ! Wakeup !    ***/
  212. /*** If TeX is not running in backround, get it started ! ***/
  213. if ~show('P','AMIGATEX') then do
  214.     address command    cmd1
  215.     if RC > 9 then okay1 'Error ! Check TeXify configuration "cmd1" for starting TeX!'
  216.     address command    cmd2
  217.     if RC > 9 then okay1 'Error ! Check TeXify configuration "cmd2" for starting TeX!'
  218.     address command    cmd3
  219.     if RC > 9 then okay1 'Error ! Check TeXify configuration "cmd3" for starting TeX!'
  220.     address command    cmd4
  221.     if RC > 9 then okay1 'Error ! Check TeXify configuration "cmd4" for starting TeX!'
  222.     address command    cmd5
  223.     if RC > 9 then okay1 'Error ! Check TeXify configuration "cmd5" for starting TeX!'
  224.     /*** now give TeX time to showup ***/
  225.     ti = time('S') + timeout;
  226.     do while ((~show('P','AMIGATEX')) & (time('S') < ti))
  227.         call delay (50)
  228.         end
  229.     if ~show('P','AMIGATEX') then do
  230.         okay2 'Error ! TeX did not get started after 'timeout' seconds !' cr||'You may start TeX now by CLI and continue !'
  231.         if result = 0 then exit 5
  232.         end
  233.     end
  234.  
  235. /*** make path of activ file current path, so TeX can find .aux ... ***/
  236. address 'AMIGATEX' 'CD' texpath
  237.  
  238. /*** check if path command is executed succesfully ***/
  239. /*** if rc = 1 then TeX is busy ***/
  240. if RC = 1 then do
  241.     okay1 'Ooops ! TeX is busy ! Try TeX in ** status !?'
  242.     exit 5
  243.     end
  244. /*** if rc = 10 then path could not been found ***/
  245. if RC = 10 then do
  246.     okay2 'ERROR ! Path ' texpath ' not accessable !' cr|| 'Shall I try it anyway ??'
  247.     if result = 0 then exit 5
  248.     end
  249.  
  250. /**** Reset counter for TeXifyLookNext.ced ***/
  251. setclip('texlog',"0")
  252.  
  253. /*** just get shure there's no old misinterpreted .log .dvi file ***/
  254. if exists(srcnam||'.log') then call delete(srcnam||'.log')
  255. if exists(srcnam||'.dvi') then call delete(srcnam||'.dvi')
  256.  
  257. /*** now texify the textfile while showing TeXs prompting ***/
  258. address 'AMIGATEX'
  259. 'ToFront'
  260.  
  261. /*** give TeX something to do... ***/
  262. 'TeXify' srcfile
  263.  
  264. /*** is TeX in input status ** ? ***/
  265. if RC = 1 then do
  266.     Okay1 'Error ! Can not TeXify your file !' cr||'TeX is not in ** status !'
  267.     exit 5
  268.     end
  269.  
  270. /*** wait until TeX gets finished ***/
  271. 'NextPrompt'
  272. 'NextPrompt'
  273.  
  274. /*** get status of TeX for analysing ***/
  275. 'Prompt'
  276. prompt = getclip('AmigaTeX.Prompt')
  277. /*** if RC = 1 then TeX was not waiting for incoming Data... ** ***/
  278. if RC = 1 then do
  279.     /*** Activate CEDPro ***/
  280.     if  ~show('P','rexx_ced') then do
  281.         address command ced||" "||fullsrc
  282.         Delay(30)
  283.         end
  284.     address 'rexx_ced'
  285.     'jump to file' fullsrc
  286.     if result = 0 then do
  287.         'Open new'
  288.         'Open' fullsrc
  289.         end
  290.     'CedToFront'
  291.  
  292.     Okay1 'Error ! TeX does not behave right !'
  293.     exit 5
  294.     end
  295.  
  296. /*** Ooops ! if this happens, there is something wrong in your source ! ***/
  297. if prompt = "?" then do
  298.     n = 1;
  299.     do while (prompt = "?" & n<=errorcount)
  300.         /*** get position of error from TeX ***/
  301.         'ErrorLoc'
  302.         error = getclip('AmigaTeX.ErrorLoc')
  303.         parse var error filename.n line.n pos.n
  304.         if n<errorcount then do
  305.             'TeXify I'||cr
  306.             'NextPrompt'
  307.             'NextPrompt'
  308.             end
  309.         n = n+1
  310.         /*** get status of TeX for analysing ***/
  311.         'Prompt'
  312.         prompt = getclip('AmigaTeX.Prompt')
  313.         if RC = 1 then do
  314.             /*** Activate CEDPro ***/
  315.             if  ~show('P','rexx_ced') then do
  316.                 address command ced||" "||fullsrc
  317.                 Delay(30)
  318.                 end
  319.             address 'rexx_ced'
  320.             'jump to file' fullsrc
  321.             if result = 0 then do
  322.                 'Open new'
  323.                 'Open' fullsrc
  324.                 end
  325.             'CedToFront'
  326.  
  327.             okay1 'Error ! TeX does not behave right !'
  328.             /*** now TeX window can disappear ***/
  329.             address 'AMIGATEX' 'ToBack'
  330.             exit 5
  331.             end
  332.         end
  333.     n = n-1
  334.     /*** now TeX can disappear ***/
  335.     'ToBack'
  336.     'Abort'
  337.  
  338.     /*** Do I have to start CEDPro? Activate CEDPro ! ***/
  339.     if  ~show('P','rexx_ced') then do
  340.         address command ced||" "||fullsrc
  341.         Delay(30)
  342.         end
  343.     address 'rexx_ced'
  344.     'jump to file' fullsrc
  345.     if result = 0 then do
  346.         'Open new'
  347.         'Open' fullsrc
  348.         end
  349.     'CedToFront'
  350.  
  351.     /*** wait a bit for TeX to finish .log file ***/
  352.     address 'AMIGATEX' 'NextPrompt'  /* TeX may need it twice... doesn't matter anyway */
  353.     address 'AMIGATEX' 'NextPrompt'
  354.     
  355.     /*** if there's no .log file, there's no explaining for your mistake ! ***/
  356.     if ~exists(srcnam|| '.log') then do
  357.         okay1 'Ooops ! Error in this line ! No .log file !'
  358.         exit 5
  359.         end
  360.  
  361.     /*** TeX may be finish with .log, but AmigaDos may need time! ***/
  362.     /*** Specially 68020/30 needs checking !                      ***/
  363.     ti = time('S') + 3;
  364.     rc = 0
  365.     do while ((rc=0) & (time('S') < ti))
  366.         rc = open('log',srcnam||'.log')
  367.         if rc = 0 then call delay(50)
  368.         end
  369.     if rc = 0 then do
  370.         okay1 "ERROR ! Error in this line !" cr|| "Can't open the existing .log file !"
  371.         exit 5
  372.         end
  373.         cause = 1
  374.         lin = 1
  375.     do until eof('log')
  376.         logline = readln('log')
  377.         if left(logline,2) = "! " then do
  378.             error.cause = right(logline,length(logline)-2)
  379.             cause = cause + 1
  380.             end
  381.         else if left(logline,2) = "l." then do
  382.             logline = subword(logline,1,1)
  383.             logline = delstr(logline,1,2)
  384.             if logline ~= line.lin then do
  385.                 pos.lin = 0
  386.                 filename.lin = "!"
  387.                 line.lin=logline
  388.                 end
  389.             lin = lin + 1
  390.             end
  391.         end
  392.     call close 'log'
  393.     lin = lin-1
  394.     if (lin > n) & (lin < errorcount) then n = lin
  395.     rc =  open('log','t:tex.log',write)
  396.     if rc = 0 then do
  397.         okay1 "ERROR ! Can't write errorfile in t: !"
  398.         exit 5
  399.         end
  400.     lin = 1
  401.     do lin = 1 for n
  402.         call writeln 'log',line.lin ||" "|| pos.lin ||" "|| filename.lin ||" "|| error.lin
  403.         end lin
  404.     call close out
  405.     setclip('texlog',"1")
  406.     setclip('texpath',path)
  407.     sfx= "."||sfx
  408.     setclip('texsfx',sfx)
  409.     'jump to file' filename.1
  410.     if result = 0 then do
  411.         if exists(path||filename.1) then do
  412.             'open new'
  413.             'open' path||filename.1
  414.             'jumpto' line.1 pos.1
  415.             okay1 error.1
  416.             exit 5
  417.             end
  418.         if exists(filename.1) then do
  419.             'open new'
  420.             'open' path||filename.1
  421.             'jumpto' line.1 pos.1
  422.             okay1 error.1
  423.             exit 5
  424.             end
  425.         'jump to file' filename.1||sfx
  426.         if result = 0 then do
  427.             if exists(path||filename.1||sfx) then do
  428.                 'open new'
  429.                 'open' path||filename.1||sfx
  430.                 'jumpto' line.1 pos.1
  431.                 okay1 error.1
  432.                 exit 5
  433.                 end
  434.             if exists(filename.1||sfx) then do
  435.                 'open new'
  436.                 'open' path||filename.1||sfx
  437.                 'jumpto' line.1 pos.1
  438.                 okay1 error.1
  439.                 exit 5
  440.                 end
  441.             'jumpto' line.1 pos.1
  442.             okay1 "Ooops ! Error in "||filename.1||"  TeX file !"||cr||error.1||cr||"Error in line:"||line.1||"  pos:" pos.1
  443.             exit 5
  444.             end
  445.         end
  446.     'jumpto' line.1 pos.1
  447.     okay1 error.1
  448.     exit 5
  449.     end
  450.  
  451.  
  452. /*** now TeX window can disappear ***/
  453. 'ToBack'
  454.  
  455. /*** if prompt = * then TeX aborted ... should be a missing \end ***/
  456. if prompt = "*" then do
  457.     'Abort'
  458.     /*** Activate CEDPro ***/
  459.     if  ~show('P','rexx_ced') then do
  460.         address command ced||" "||fullsrc
  461.         Delay(30)
  462.         end
  463.     address 'rexx_ced'
  464.     'jump to file' fullsrc
  465.     if result = 0 then do
  466.         'Open new'
  467.         'Open' fullsrc
  468.         end
  469.     'CedToFront'
  470.     okay1 'Ooops ! TeX ended in * status !' cr|| 'Maybe a forgotten \end ??'
  471.     exit 5
  472.     end
  473.  
  474. /*** seems that everything worked fine with tex ***/
  475. if prompt = '**' then do
  476.     /*** pop up CygnusEd screen, so you get there when quiting preview ***/
  477.     if  show('P','rexx_ced') then do
  478.         address 'rexx_ced' 
  479.         'CEDTOFRONT'
  480.         end
  481.  
  482.     /*** cut suffix from sourcefiles name; preview don't like suffix ***/
  483.     fullsrc = left(fullsrc,lastpos('.',fullsrc)-1)
  484.  
  485.     /*** do I have to start preview first ? ***/ 
  486.     if  ~show('P','TEXPREVIEW') then  address command preview||" "||fullsrc
  487.     else do
  488.         address 'TEXPREVIEW'
  489.         'ToFront'
  490.         'activate'
  491.         end
  492.  
  493.     /*** now give preview time to showup ***/
  494.     ti = time('S') + timeout;
  495.     do while ((~show('P','TEXPREVIEW')) & (time('S') < ti))
  496.         call delay(50)
  497.         end
  498.     if ~show('P','TEXPREVIEW') then do
  499.         /*** Activate CEDPro ***/
  500.         if  ~show('P','rexx_ced') then do
  501.             address command ced||" "||fullsrc
  502.             Delay(30)
  503.             end
  504.         address 'rexx_ced'
  505.         'jump to file' fullsrc
  506.         if result = 0 then do
  507.             'Open new'
  508.             'Open' fullsrc
  509.             end
  510.         'CedToFront'
  511.         okay1 "ERROR ! Couldn't start Preview after "timeout" secs !" cr||"       You may start Preview now by CLI !" cr||"       Your .dvi file seems to be fine !"
  512.         exit 5
  513.         end
  514.     address 'TEXPREVIEW' 'cd '||texpath
  515.     exit
  516.     end
  517.  
  518. /*** unknown prompt from TeX !!!!!! ***/
  519. /*** now TeX can disappear ***/
  520. 'ToBack'
  521. 'Abort'
  522. /*** Activate CEDPro ***/
  523. if  ~show('P','rexx_ced') then do
  524.     address command ced||" "||fullsrc
  525.     Delay(30)
  526.     end
  527. address 'rexx_ced'
  528. 'jump to file' fullsrc
  529. if result = 0 then do
  530.     'Open new'
  531.     'Open' fullsrc
  532.     end
  533. 'CedToFront'
  534. /*** wait a bit for TeX to finish .log file ***/
  535. 'NextPrompt'  /* TeX may need it twice... doesn't matter anyway */
  536. 'NextPrompt'
  537.  
  538. /*** if there's no .log file, there's no explaining for your mistake ! ***/
  539. if ~exists(srcnam|| '.log') then do
  540.     okay1 'Ooops ! TeX aborted in  unknown status !'|| cr || "Can't open any .log file !"
  541.     exit 5
  542.     end
  543. /*** TeX may be finish with .log, but AmigaDos may need time! ***/
  544. /*** Specially 68020/30 needs checking !                      ***/
  545. ti = time('S') + 3;
  546. rc = 0
  547. do while ((rc=0) & (time('S') < ti))
  548.     rc = open('log',srcnam||'.log')
  549.     if rc = 0 then call delay(50)
  550.     end
  551. if rc = 0 then do
  552.     okay1 "ERROR ! TeX aborted in unknown status !"||cr||"Can't open the existing .log file !"
  553.     exit 5
  554.     end
  555. logline = ""
  556. do until (left(logline,2) = "! " )
  557.     logline = readln('log')
  558.     if eof('log') then do
  559.         /*** no '! ' found in file ***/
  560.         call close 'log'
  561.         okay1 "Ooops !  TeX aborted in unknown status !"||cr||"No error in .log file ! Try it by hand !"
  562.         exit 5
  563.         end
  564.     end
  565. errline = ""
  566. do until (left(errline,2) = "l.")
  567.     errline = readln('log')
  568.     if eof('log') then do
  569.         /*** no '! ' found in file ***/
  570.         call close 'log'
  571.         okay1 "Ooops !  TeX aborted in unknown status !"||cr||"There is an unknown error in TeX file !!!"
  572.         exit 5
  573.         end
  574.     end
  575. call close 'log'
  576. errline = subword(errline,1,1)
  577. errline = delstr(errline,1,2)
  578. /*** '! ' found in .log file; show error explanation ***/
  579. logline = right(logline,length(logline)-2)
  580. strip(logline,'B')
  581. 'jumpto' errline 1
  582. okay1 "Ooops !  TeX aborted in unknown status !"||cr||"Error in unknown TeX source ! Line: "||errline||cr||logline
  583. exit 5
  584. end
  585.